import re


def get_name_size(filename):
    data = None  # 存储数据
    with open(filename, 'r') as f:
        data = f.read()  # 读入数据
    # 保存输入节点信息
    input_list = []
    # 保存输出节点信息
    output_list = []
    # 取出输入节点包含文本匹配
    result = re.search(r"=== Automatically deduced input nodes ===.*?===", data, re.S)
    # print(result.group((0)))
    if result:
        input_data = result.group(0)  # 输入节点包含文本
        # 取出所有的name节点信息匹配
        names = re.findall(r"name.*?\,|name.*?\]", input_data, re.S)
        # print(len(names))
        if len(names) > 0:
            for name in names:
                # 找到所有name和size信息
                info = re.findall(r"name.*|size.*", name, re.M)
                if len(info) > 0:
                    name_list = []
                    # 取出所有name属性值和size值
                    for val in info:
                        pos = val.find(":")
                        if pos >= 0:
                            name_list.append(val[pos + 1:].replace('"', '').strip(" "))
                    input_list.append(name_list)

    # 取出输出节点包含文本匹配
    result = re.search(r"=== Automatically deduced output nodes ===.*?===", data, re.S)
    # print(result.group((0)))
    if result:
        output_data = result.group(0)  # 输出节点包含文本
        # 取出所有的name节点信息匹配
        names = re.findall(r"name.*?\,|name.*?\]", output_data, re.S)
        # print(len(names))
        if len(names) > 0:
            for name in names:
                # 找到所有name
                info = re.findall(r"name.*", name, re.M)
                if len(info) > 0:
                    # 取出所有name属性值
                    for val in info:
                        pos = val.find(":")
                        if pos >= 0:
                            output_list.append(val[pos + 1:].replace('"', '').strip(" "))

    return input_list, output_list


if __name__ == "__main__":
    input_list, output_list = get_name_size("record.txt")
    print(input_list, output_list)
